#首先 import 必要的模块
import numpy as np
import pandas as pd

import matplotlib.pyplot as plt
import seaborn as sns
train = pd.read_csv("./pima-indians-diabetes.csv")
#print(train.head())
print("Train :", train.shape)
print("Train :", train.info())
print(train.describe())
NaN_col_names = ['Plasma_glucose_concentration','blood_pressure','Triceps_skin_fold_thickness','serum_insulin','BMI']
print((train[NaN_col_names] == 0).sum())
#该问题为分类问题，类别型特征直方图可用countplot
sns.countplot(train['Target'])
plt.xlabel('Diabetes')
plt.ylabel('Number of occurrences')
plt.show()
#1.怀孕次数pregnants
fig = plt.figure()
### Number of occurrences
sns.countplot(train['pregnants'])
plt.xlabel('Number of pregnants')
plt.ylabel('Number of occurrences')
plt.show()
#怀孕次数和是否发病是否有关系
sns.countplot(x="pregnants", hue="Target",data=train)
plt.show()
#2 血浆葡萄糖浓度
fig = plt.figure()
sns.distplot(train.Plasma_glucose_concentration, kde = False)
plt.xlabel('Plasma_glucose_concentration')
plt.ylabel('Number of occurrences')
#血浆葡萄糖浓度和是否发病关系
sns.violinplot(x='Target', y='Plasma_glucose_concentration', data=train, hue="Target")
plt.xlabel('Diabetes', fontsize=12)
plt.ylabel('Plasma_glucose_concentration', fontsize=12)
plt.show()
#3 血压
fig = plt.figure()
sns.distplot(train.blood_pressure, kde = False)
plt.xlabel('blood_pressure')
plt.ylabel('frequency')
# 血压和标签之间的关系
sns.violinplot(x='Target', y='blood_pressure', data=train, hue="Target")
plt.xlabel('Diabetes', fontsize=12)
plt.ylabel('blood_pressure', fontsize=12)
plt.show()
#4.三头肌皮褶厚度
fig = plt.figure()
sns.distplot(train.Triceps_skin_fold_thickness, kde = False)
plt.xlabel('Triceps_skin_fold_thickness')
plt.ylabel('frequency')
#三头肌皮褶厚度和是否发病关系
sns.violinplot(x='Target', y='Triceps_skin_fold_thickness', data=train, hue="Target")
plt.xlabel('Diabetes', fontsize=12)
plt.ylabel('Triceps_skin_fold_thickness', fontsize=12)
plt.show()
#5.餐后血清胰岛素浓度
fig = plt.figure()
sns.distplot(train.serum_insulin, kde = False)
plt.xlabel('serum_insulin')
plt.ylabel('frequency')
#餐后血清胰岛素浓度和是否发病关系
sns.violinplot(x='Target', y='serum_insulin', data=train, hue="Target")
plt.xlabel('Diabetes', fontsize=12)
plt.ylabel('serum_insulin', fontsize=12)
plt.show()
#6   BMI
fig = plt.figure()
sns.distplot(train.BMI, kde = False)
plt.xlabel('BMI')
plt.ylabel('frequency')
#  BMI和是否发病关系
sns.violinplot(x='Target', y='BMI', data=train, hue="Target")
plt.xlabel('Diabetes', fontsize=12)
plt.ylabel('BMI', fontsize=12)


BMIDF = train.groupby(['BMI', 'Target'])['BMI'].count().unstack('Target').fillna(0)
BMIDF[[0,1]].plot(kind='bar', stacked=True)
plt.show()
#7糖尿病家系作用
###Diabetes_pedigree_function，糖尿病家系作用
fig = plt.figure()
sns.distplot(train.Diabetes_pedigree_function, kde = False)
plt.xlabel('Diabetes_pedigree_function')
plt.ylabel('frequency')
#  糖尿病家系作用和是否发病关系
DF = train.groupby(['Diabetes_pedigree_function', 'Target'])['Diabetes_pedigree_function'].count().unstack('Target').fillna(0)
DF[[0, 1]].plot(kind='bar', stacked=True)
plt.show()
#Age
fig = plt.figure()
sns.distplot(train.Age, kde = False)
plt.xlabel('Age')
plt.ylabel('frequency')
#  Age和是否发病关系
DF = train.groupby(['Age', 'Target'])['Age'].count().unstack('Target').fillna(0)
DF[[0,1]].plot(kind='bar', stacked=True)
plt.show()

for feature in train.columns:
    sns.distplot(train[feature],kde = False)
    plt.show()
#特征和特征之间的关系
data_corr = train.corr().abs()
plt.subplots(figsize=(13, 9))
sns.heatmap(data_corr,annot=True)
plt.show()

